var endTime = new Date("2019-12-12 00:00:00"), endSeconds = endTime.getTime();//设置秒杀结束时间
var d = h = m = s = 0;//定义变量保存剩余的时间
var id = setInterval(seckill, 1000);//设置定时器，实现限时秒杀效果
function seckill() {
    var nowTime = new Date();//获取当前时间
    var remaining = parseInt((endSeconds - nowTime.getTime()) / 1000);//获取时间差 单位为秒
    if (remaining > 0) {//判断秒杀是否过期
        d = parseInt(remaining / 86400); //计算剩余天数(除以60*60*24取整，获取剩余天数)
        h = parseInt((remaining / 3600) % 24);//计算剩余小时(除以60*60转换为小时，与24取模，获取剩余)
        m = parseInt((remaining / 60) % 60);
        s = parseInt(remaining % 60);
        d = d < 10 ? "0" + d : d;
        h = h < 10 ? "0" + h : h;
        m = m < 10 ? "0" + m : m;
        s = s < 10 ? "0" + s : s;
    } else {
        clearInterval(id);//秒杀过期
        d = h = m = s = '00';
    }
    document.getElementById("d").innerHTML = d + "天";
    document.getElementById("h").innerHTML = h + "时";
    document.getElementById("m").innerHTML = m + "分";
    document.getElementById("s").innerHTML = s + "秒";
}